package com.atguigu.service.Impl;

import com.atguigu.config.HttpUtils;
import com.atguigu.service.MsmService;
import org.apache.http.HttpResponse;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class MsmServiceImpl implements MsmService {
    @Override
    public boolean send(String phone, String code) {
        String host = "http://dingxin.market.alicloudapi.com";
        String path = "/dx/sendSms";
        String method = "POST";
        String appcode = "7c98cececd29448f9fb38e28f930c05b";
        Map<String, String> map = new HashMap<>();
        map.put("Authorization", "APPCODE " + appcode);
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        Map<String, String> querys = new HashMap<>();
        querys.put("mobile", phone);
        querys.put("param", "code:" + code);
        querys.put("tpl_id", "TP1711063");

        Map<String, String> bodys = new HashMap<String, String>();
        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, map, querys, bodys);
            System.out.println(response.toString());
            return true;
        } catch (Exception e) {
            return false;
        }

    }
}
